import req from '@/utils/request'
import type { SkuListData, SKuType } from '@/api/product/model/SkuListType'
import type {
  SaveSkuInfoParams,
  SpuSaleAttrListType,
} from '@/api/product/model/SPUType'
enum Api {
  skuList = '/admin/product/list',
  getSkuById = '/admin/product/getSkuById',
  onSale = '/admin/product/onSale',
  cancelSale = '/admin/product/cancelSale',
  updateSkuInfo = '/admin/product/updateSkuInfo',
  spuSaleAttrList = '/admin/product/spuSaleAttrList',
}

// 获取sku列表
export const getSkuListApi = (page: number, limit: number) => {
  return req.get<null, SkuListData>(`${Api.skuList}/${page}/${limit}`)
}

// 获取单个sku信息
export const getSkuByIdApi = (id: number) => {
  return req.get<null, SKuType>(`${Api.getSkuById}/${id}`)
}

// 商品上架
export const setOnSaleApi = (id: number) => {
  return req.get<null, null>(`${Api.onSale}/${id}`)
}
// 取消上架
export const cancelSaleApi = (id: number) => {
  return req.get<null, null>(`${Api.cancelSale}/${id}`)
}

// 修改sku信息
export const updateSkuInfoApi = (data: SaveSkuInfoParams) => {
  return req.post<null, null>(Api.updateSkuInfo, data)
}

// 获取商品基础属性信息by spuId
export const getSpuSaleAttrListApi = (id: number) => {
  return req.get<null, SpuSaleAttrListType>(`${Api.spuSaleAttrList}/${id}`)
}
